package com.modemMgr.dao;

import java.sql.SQLException;

import com.modemMgr.util.DBAccessor;
import com.modemMgr.vo.WarehouseDetail;

public class WarehouseDetailDAO extends BaseDAO{
	public WarehouseDetailDAO(DBAccessor dbAccessor) {
		super(dbAccessor);
	}

	public WarehouseDetail getWarehourseDetail(int warehouseId, int itemId) throws Exception
	{
		String sql = "select * from warehouse_detail where warehouse_id = ? and item_id = ?";
		Object[] params = new Object[]{warehouseId, itemId};
		WarehouseDetail warehouseDetail = dbAccessor.queryObject(WarehouseDetail.class, sql, params);
		return warehouseDetail;
	}
	
	public void addWarehouseDetail(int warehouseId, int itemId, int quantity) throws SQLException
	{
		String sql = "insert into warehouse_detail(warehouse_id, item_id, quantity) values(?, ?, ?)";
		Object[] params = new Object[]{warehouseId, itemId, quantity};
		dbAccessor.update(sql, params);
	}
	
	public void modifyWarehouseDetail(WarehouseDetail detail) throws SQLException
	{
		String sql = "update warehouse_detail set quantity = ? where warehouse_id = ? and item_id = ?";
		Object[] params = new Object[]{detail.getQuantity(), detail.getWarehouse_id(), detail.getItem_id()};
		dbAccessor.update(sql, params);
	}
}
